package yto.freemarker.springcloud.controller;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import yto.freemarker.springcloud.entity.User;
import yto.freemarker.springcloud.service.UserService;

/**
 * @author dongxing
 * @create 2018-02-27 22:16
 **/
@RestController
@Slf4j
@AllArgsConstructor(onConstructor = @_(@Autowired))
public class UserController {

    private UserService userService;

    private final RestTemplate restTemplate;

    @GetMapping("/user/{id}")
    public User findById(@PathVariable Integer id) {

        return userService.getUserById(id);

    }

    /**
     * 远程服务
     * @return
     */
    @GetMapping( "/index")
    public Object sleuthProviderIndex() {
        log.info("<<<<<<<<<<<<<<<<calling trace demo provider>>>>>>>>>>>>>>>");
        String str = restTemplate.getForEntity("http://service-provider-with-sleuth/index", String.class).getBody();
        return str;
    }
}
